package com.share.server;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @date 2018/05/20
 * @author caifan
 *
 */
@SpringBootApplication
@EnableEurekaServer
@RestController
@RequestMapping("/rest")
public class EurekaServerApplication extends SpringBootServletInitializer {
    @Autowired
    Environment environment;

    public static void main(String[] args) {
//        SpringApplication.run(EurekaServerApplication.class, args);
//        new SpringApplicationBuilder(EurekaServerApplication.class).web(true).run(args);// old version
        new SpringApplicationBuilder(EurekaServerApplication.class).web(WebApplicationType.SERVLET).run(args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(EurekaServerApplication.class);
    }

    @RequestMapping(value = "/config", method = RequestMethod.GET)
    public String getConfigPort(@RequestParam String configName) {
        return environment.getProperty(configName);
    }
}
